/*
 * Create by wangy
 * Date:2010-09-16
 */
function search(){
    document.homeForm.submit();
}

function searchInfo(){
    document.homeForm.submit();
}

function trim(str){
    return str.replace(/(^\s*)|(\s*$)/g,'');
  }//去掉空格

function chekedform() {

	var str = CKEDITOR.instances.reason.getData();
	str = str.replace('<br />','');
 	str = str.replace('<br>','');
 	str = trim(str);
	if(str == ''){
  	alert('请填写退货原因!');
  	CKEDITOR.instances.reason.focus();
		return false;
	}
  document.addForm.submit();
}

function modifyform() {

	var str = CKEDITOR.instances.content.getData();
	str = str.replace('<br />','');
 	str = str.replace('<br>','');
 	str = trim(str);
	if(str == ''){
  	alert('请填写退货原因!');
  	CKEDITOR.instances.content.focus();
		return false;
	}
  document.addForm.submit();
}


function selectOrder(){

	var order = document.getElementsByName("order");
	for ( var i = 0; i < order.length; i++ ){
		var listsize = document.getElementById('checksize_' + i).value;
		if( order[i].checked ) {
			for( var k = 0; k < listsize; k++ ){
				document.getElementById('check_' + i + '_' + k).disabled = false;
				document.getElementById('line' + i).bgColor = '#fdfbd5';
			}
		}else{
			for( var k = 0; k < listsize; k++ ){
				document.getElementById('check_' + i + '_' + k).disabled = true;
				document.getElementById('line' + i).bgColor = '';
			}
		}
	}
}

function ifStateNull(){
	var order = document.getElementsByName('order');
	for ( var i = 0; i < order.length; i++ ){
		var listsize = document.getElementById('checksize_' + i).value;
		if( order[i].checked ) {
			order_string = document.getElementById('order_id_' + i).value;
			for( var k = 0; k < listsize; k++ ){
				if( document.getElementById('check_' + i + '_' + k).checked ){
					if( document.getElementById('state_' + i + '_' + k).value != '' ){
						alert('只能选择未申请商品提交,请重新选择!');
						document.getElementById('check_' + i + '_' + k).checked = false;
					}
				}
			}
		}
	}
}

function checkReturnGoods(){

	var pkid_string = '';
	var cust_string = '';
	var order_string = '';

	var order = document.getElementsByName('order');

	for ( var i = 0; i < order.length; i++ ){
		var listsize = document.getElementById('checksize_' + i).value;
		if( order[i].checked ) {
			order_string = document.getElementById('order_id_' + i).value;
			for( var k = 0; k < listsize; k++ ){
				if( document.getElementById('check_' + i + '_' + k).checked ){
					if( document.getElementById('state_' + i + '_' + k).value != '' ){
						alert('只能选择未申请商品提交,请重新选择!');
						document.getElementById('check_' + i + '_' + k).checked = false;
						return false;
					}else {
						pkid_string += document.getElementById('check_' + i + '_' + k).value + '|';

						cust_string = document.getElementById('cust_id_' + i + '_' + k).value + '|';
						if((cust_string.indexOf(document.getElementById('cust_id_' + i + '_' + k).value) == -1) && cust_string != ''){
							cust_string += document.getElementById('cust_id_' + i + '_' + k).value + '|';
						}
					}
				}
			}
		}
	}
	if( pkid_string == '' ){
		alert('请选择需要退货的商品!');
		return false;
	}
	var menu_id = document.getElementById('menu_id').value;
	//document.getElementById('pkid').value = pkid_string;
	//document.getElementById('cust_id_group').value = cust_string;

	document.homeForm.action='/doTradeReg.do';
	if(window.confirm('确认提交吗?')){
		//document.homeForm.submit();
		window.location.href = 'addindex.jsp?menu_id='+menu_id+'&order_string='+order_string+'&cust_string='+cust_string+'&pkid_string='+pkid_string;
	}
}